home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1988 / 05 / 65l1.asm next >
Assembly Source File  |  1988-08-18  |  4KB  |  179 lines

  1. Copyright Michael Abrash, 1988.  All Rights Reserved.
  2. ;
  3. ; Program to demonstrate the 4 text pages of the CGA.
  4. ;
  5. ; To demonstrate the 8 standard text pages of the VGA/EGA,
  6. ; change NUMBER_OF_PAGES from 4 to 8.
  7. ;
  8. ; To demonstrate the 16 text pages available on the VGA/EGA
  9. ; when display memory is relocated to A000, change NUMBER_OF_PAGES
  10. ; to 16 and change RELOCATE_TO_A000 from 0 to 1.
  11. ;
  12. ; To demonstrate that the upper 8 text pages can be displayed even
  13. ; when the CPU can't access them, change NUMBER_OF_PAGES to 16,
  14. ; RELOCATE_TO_A000 to 1, and RELOCATE_BACK_TO_B800 to 1.
  15. ;
  16. ; By Michael Abrash  5/22/88
  17. ;
  18.  
  19. NUMBER_OF_PAGES        equ    4
  20. RELOCATE_TO_A000    equ    0
  21. RELOCATE_BACK_TO_B800    equ    0
  22. PAGE_LENGTH        equ    1000h    ;number of bytes per page
  23.  
  24. if RELOCATE_TO_A000
  25. DISPLAY_MEMORY_SEGMENT    equ    0a000h
  26. else
  27. DISPLAY_MEMORY_SEGMENT    equ    0b800h
  28. endif
  29.  
  30. GC_INDEX        equ    3ceh
  31. GC_MISCELLANEOUS    equ    6
  32. CRTC_INDEX        equ    3d4h
  33. CRTC_START_ADDRESS_HIGH    equ    0ch
  34. CRTC_START_ADDRESS_LOW    equ    0dh
  35.  
  36. stack    segment    para stack 'STACK'
  37.     db    512 dup (?)
  38. stack    ends
  39.  
  40. code    segment para public 'CODE'
  41.     assume    cs:code, ds:nothing
  42. start    proc    near
  43. ;
  44. ; Set to text mode.
  45. ;
  46.     mov    ax,3
  47.     int    10h
  48. ;
  49. ; Relocate display memory to A000 if necessary, by reprogramming
  50. ; the Graphics Controller's Miscellaneous register.
  51. ;
  52. if RELOCATE_TO_A000
  53.     mov    dx,GC_INDEX
  54.     mov    al,GC_MISCELLANEOUS
  55.     out    dx,al
  56.     inc    dx
  57.     mov    al,06h
  58.     out    dx,al
  59. endif
  60. ;
  61. ; Point to the segment that display memory is currently
  62. ; addressed at.
  63. ;
  64.     mov    ax,DISPLAY_MEMORY_SEGMENT
  65.     mov    es,ax
  66. ;
  67. ; Fill each of the text screens in turn with an appropriate character.
  68. ; (Page 0 is filled with "A", page 1 with "B", and so on.)
  69. ;
  70.     sub    ax,ax    ;start with page 0
  71.     mov    bl,'A'    ;base letter
  72. FillPageLoop:
  73.     push    ax
  74.     call    FillPage
  75.     pop    ax
  76.     inc    ax
  77.     cmp    ax,NUMBER_OF_PAGES
  78.     jb    FillPageLoop
  79. ;
  80. ; Relocate display memory back to B800 if necessary,
  81. ; by reprogramming the Graphics Controller's Miscellaneous
  82. ; register, to illustrate the principle that it's possible to
  83. ; display the upper 8 pages even when the CPU can't access them.
  84. ;
  85. if RELOCATE_BACK_TO_B800
  86.     mov    dx,GC_INDEX
  87.     mov    al,GC_MISCELLANEOUS
  88.     out    dx,al
  89.     inc    dx
  90.     mov    al,0Eh
  91.     out    dx,al
  92. endif
  93. ;
  94. ; Display each of the text pages in turn, waiting for a key
  95. ; before going to the next page.
  96. ;
  97.     sub    ax,ax
  98. ShowPageLoop:
  99.     push    ax
  100.     call    ShowPage
  101.     call    WaitKey
  102.     pop    ax
  103.     inc    ax
  104.     cmp    ax,NUMBER_OF_PAGES
  105.     jb    ShowPageLoop
  106. ;
  107. ; Done-perform a mode set to reset all paging and clear
  108. ; the screen, then return to DOS.
  109. ;
  110.     mov    ax,3
  111.     int    10h
  112.     mov    ah,4ch
  113.     int    21h
  114. start    endp
  115. ;
  116. ; Fills a text page with a corresponding character.
  117. ;
  118. ; Input:
  119. ;    AX = text page
  120. ;    BL = character for text page 0 (each text page
  121. ;        is filled with character BL + text page #)
  122. ;
  123. FillPage    proc    near
  124.     push    ax    ;save the page #
  125.     mov    dx,PAGE_LENGTH
  126.     mul    dx    ;calculate the start offset of the page
  127.             ; in the display memory segment
  128.     mov    di,ax
  129.     pop    ax    ;get back the page #
  130.     add    al,bl    ;convert it to a unique letter
  131.     mov    ah,7    ;attribute is white
  132.     mov    cx,PAGE_LENGTH/2 ;page length as measured
  133.                  ; in character/attribute pairs
  134.     cld
  135.     rep    stosw    ;fill the page
  136.     ret
  137. FillPage    endp
  138. ;
  139. ; Programs the CRTC to display the desired text page.
  140. ;
  141. ; Input: AX = text page.
  142. ;
  143. ShowPage    proc    near
  144.     mov    dx,PAGE_LENGTH/2
  145.     mul    dx        ;start offset of the pages as
  146.                 ; measured in character/attribute
  147.                 ; pairs (which is how the CRTC
  148.                 ; counts in text mode)
  149.     mov    dx,CRTC_INDEX    ;point to the CRTC Index register
  150.     push    ax
  151.     mov    al,CRTC_START_ADDRESS_HIGH
  152.     out    dx,al
  153.     inc    dx        ;point to the CRTC Data register
  154.     mov    al,ah
  155.     out    dx,al        ;set the high start address byte
  156.     dec    dx        ;point to the CRTC Index register
  157.     mov    al,CRTC_START_ADDRESS_LOW
  158.     out    dx,al
  159.     inc    dx        ;point to the CRTC Data register
  160.     pop    ax
  161.     out    dx,al        ;set the low start address byte
  162.     ret
  163. ShowPage    endp
  164. ;
  165. ; Waits until a key is pressed.
  166. ;
  167. WaitKey    proc    near
  168.     mov    ah,1
  169.     int    16h
  170.     jz    WaitKey
  171.     sub    ah,ah
  172.     int    16h    ;clear the key
  173.     ret
  174. WaitKey    endp
  175.  
  176. code    ends
  177.     end    start
  178.  
  179.